from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import time

driver = webdriver.Chrome(executable_path=r"D:\python\chromedriver.exe")
driver.get(r"C:\Users\小莹莹\PycharmProjects\UI自动化测试\注册A.html")

try:
    # 显式等待下拉框加载
    city_element = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.NAME, "city"))
    )
    city_select = Select(city_element)

    # 选择‘广州’
    city_select.select_by_visible_text("广州")
    time.sleep(2)

    # 选择‘上海’
    city_select.select_by_visible_text("上海")
    time.sleep(2)

    # 选择‘北京’
    city_select.select_by_visible_text("北京")
    time.sleep(2)

finally:
    driver.quit()